﻿@model IEnumerable<DistributeTransaction.Models.Order>
@{
    ViewBag.Title = "Orders";
    Layout = "~/Views/Shared/_Layout.cshtml";
    WebGrid grid = new WebGrid(
        source: Model,
        defaultSort: "OrderDate",
        sortFieldName: "OrderDate",
        sortDirectionFieldName: "sortdir"
       );
        
    // Force a descending sort only when no user specified sort is present
    if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty())
    {
        grid.SortDirection = SortDirection.Descending;
    }
}
<h2>
    Orders
</h2>
@using (Html.BeginForm())
{
    <fieldset>
        <legend></legend>
@grid.GetHtml(
　　 tableStyle: "webgrid", 
     headerStyle: "webgrid-heade",
     footerStyle: "webgrid-footer",
     alternatingRowStyle: "webgrid-alternating-row",
     selectedRowStyle: "webgrid-selected-row",
     rowStyle: "webgrid-row-style",
     columns: grid.Columns(
            grid.Column(format: (item) => Html.ActionLink("Detail", "Detail", new { orderId = item.OrderId })),
            grid.Column(
                    columnName: "Status",
                    header: "Status",
                    style: "text-align-left"
                    ),        
            grid.Column(
                     columnName: "OrderDate",
                         header: "Order Date",
                         style:  "text-align-center",
                         format: (item)=> string.Format("{0:MMM/dd/yyyy}", item.OrderDate)
                        ),
            grid.Column(
                        columnName: "ShippedDate",
                        header: "Shipped Date",
                        style:  "text-align-center",
                        format: (item) => (item.ShippedDate == null ? item.ShippedDate : string.Format("{0:MMM/dd/yyyy}", item.ShippedDate))
                        ),
            grid.Column(
                    columnName: "ShipName", 
                    header: "Ship Name",
                    style: "text-align-center"
                    ),
            grid.Column(
                    columnName: "ShipAddress",
                    header: "Shipped Address",
                    style: "text-align-center"),
            grid.Column(
                    columnName: "Freight",
                    header: "Freight",
                    style: "text-align-right",
                    format: (item) => string.Format("{0:C}", item.Freight)
                    )
            )
        )
    </fieldset>
}
